require(["core", "jQuery", "coAjax", "hash_routie", "queryString", "href"], function(jSouper, $, coAjax, hash_routie, QueryString, href) {
	function _setNewsToCache (newsInstance) {
		App.set("$Cache.news_update", newsInstance.info);
		App.set("$Cache.news_update.news_id", newsInstance._id);
	}
	hash_routie.on("newsupdate", function() {
		var query = new QueryString(location.hash);
		var news_id = query.get("news_id");
		if (!news_id) {
			alert("error", "无效的动态编号");
			href.jump("#admin/newsup");
		}
		coAjax.get(appConfigPub.open.news_by_id, {
			news_id: news_id
		}, function(result) {
			_setNewsToCache(result.result);
		});
	});
	App.set("$Event.admin.update_news", function() {
		var news_id = App.get("$Cache.news_update.news_id")
		var news_title = App.get("$Cache.news_update.title");
		var news_author = App.get("$Cache.news_update.author");
		var news_content = App.get("$Cache.news_update.content");
		coAjax.put(appConfig.admin.update_news, {
			news_id: news_id,
			info: {
				title: news_title,
				author: news_author,
				content: news_content
			}
		}, function(result) {
			alert("success", "动态修改成功");
			//重置缓存
			_setNewsToCache(result.result);
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
		});
	});
});